package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.service.SetmealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/address")
public class AddressController {

    @Reference
    private SetmealService setmealService;

    /**
     * 查询所有地址
     * @return
     */
    @RequestMapping("findAllAddress")
    public Result findAllAddress(){
        try {
            List<Map<String,Object>> all = setmealService.findAllAddress();
            List<String> list = new ArrayList<>();
            for (Map<String, Object> map : all) {
                String name = (String) map.get("name");
                list.add(name);
            }
            return new Result(true,"获取地址成功",list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"获取地址失败");
        }
    }
}
